package org.yelongframework.image.javaawt.graphics;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.imageio.ImageIO;

import org.yelongframework.image.graphics.ImageGraphicsSupport;

/**
 * awt 图片图形工具实现
 * 
 * @since 1.0.0
 */
public class DefaultJavaawtImageGraphicsSupport implements ImageGraphicsSupport {

	/** 默认图片类型 */
	public static final String DEFAULT_IMAGE_TYPE = "jpg";

	// ==================================================画矩阵==================================================

	@Override
	public OutputStream drawRect(InputStream inputStream, int x, int y, int width, int height, Color color,
			OutputStream outputStream) throws IOException {
		return drawRect(inputStream, x, y, width, height, color, DEFAULT_IMAGE_TYPE, outputStream);
	}

	@Override
	public OutputStream drawRect(InputStream inputStream, int x, int y, int width, int height, Color color,
			String imageType, OutputStream outputStream) throws IOException {
		BufferedImage image = ImageIO.read(inputStream);
		Graphics g = image.getGraphics();
		g.setColor(color);
		g.drawRect(x, y, width, height);
		ImageIO.write(image, imageType, outputStream);
		return outputStream;
	}

}
